package com.juyu.miliao.api.dao.mysql;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.juyu.miliao.api.domain.vo.UserCashVo;
import com.juyu.miliao.common.dataSource.tool.operate.Operate;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.juyu.miliao.api.domain.UserCash;

@Repository
public class UserCashDao {
	@Autowired
	private SqlSession sqlSession;

	public int insertUserCash(UserCash entity){
		return sqlSession.insert("insertUserCash", entity);
	}

	public List<UserCashVo> getUserCashList(long userId, int startNum, int pageSize){
		Map<String, Object> params = new HashMap<>();
		params.put("userId", userId);
		params.put("startNum", startNum);
		params.put("pageSize", pageSize);
		return sqlSession.selectList("getUserCashList", params);
	}

	public int getCountUserCash(int userId, String date){
		Map<String, Object> params = new HashMap<>();
		params.put("userId", userId);
		params.put("date", date);
		return sqlSession.selectOne("getCountUserCash", params);
	}

	@Operate("strategy('byUserId', #userId)")
    public UserCash getUserCashInfoByUserId(long userId) {
		return sqlSession.selectOne("getUserCashInfoByUserId", userId);
    }

	@Operate("strategy('byUserId', #entity.userId)")
	public int insertUserCashInfo(UserCash entity) {
		return sqlSession.insert("insertUserCashInfo", entity);
	}
}
